#include "public.h"
vector<string>  readfileline(string filepath){
    char data[200];
    int x=0;
    vector<string> g_vec;
    ifstream infile;
    infile.open(filepath);
    if(!infile.is_open()){
        cerr << "open failed!" << endl;
        g_vec.emplace_back("NO DATA!");
        return g_vec;
    }
    while(!infile.eof()) {
        infile.getline(data, sizeof(data));
        g_vec.emplace_back(data);
        x++;
    }
    if (g_vec.size()==x){
        log(FUNC,GEN," read file get vector is " , strcolorA(GREEN,"successful!!!"),",len is ",g_vec.size());
    }
//
    return g_vec;
}
string **array_transf(int & GRowsNum ){
    log(FUNC,INFO,"function array_transf()");
    string filepathstr ="..//SH#600000.txt";
    vector<string> v =readfileline(filepathstr);
    cout << "\tvector size =("<< v.size()<<")"<<endl;
    int start =1;
    int end=v.size()-2;
    GRowsNum=v.size();
    const int rowsNum = v.size();
    int columnsNum = 7;

    // 两维都不知道
    string **a;
    a = new string * [rowsNum];
//    cout <<"========================================================"<<endl;
//    for (int i = 0; i < rowsNum; i++) {
//        a[i] = new string [columnsNum];
//        for (int j = 0; j < columnsNum; j++) {
//            a[i][j] = "[i="+to_string(i)+",j="+to_string(j)+"]";
////            cout <<"["<<i<<"]" << a[i][j] <<"," ;
//        }
////        printf("\n");
//    }


    for (int i = 0; i < rowsNum; i++){
        a[i] = new string [columnsNum];
        if(i>start && i<end){
            string oldstr=v[i];

            cout <<"\t";
            for (int j = 0; j < columnsNum; j++) {
                string* newstr=new string[columnsNum];
                int s=0;
                for (int k = 0; k < oldstr.length(); k++) {
                    if (oldstr[k] == '\t') {                 //以空格作为分隔符
                        s++;
                        continue;
                    }
                    newstr[s] += oldstr[k];
                }
                a[i][j]=newstr[j];
//                cout << "[" << a[i][j] << "]";
            }
//           printf("\n");
        }


    }
//    cout <<"========================================================"<<endl;
//    printf("\t\t%d\n", sizeof(a));

//    for (int i = 0; i < rowsNum; i++) {
//        delete [] a[i];
//    }
//    delete [] a;
//cout << "GRowsNum="<<GRowsNum<<endl;
    return a;
}
void p(){
    log(FUNC,INFO,"function p()");
    int sum=0;
    string **a =array_transf(sum);
    cout << "array_transf"<< strcolor(RED, to_string(sum)) <<endl;
    for(int i=0;i<sum;i++){
        for(int j=0;j<7;j++){
            cout << "[" << a[i][j] << "]";
        }
        printf("\n");
    }
}
int show(int x,int y){
    log(FUNC,INFO,"function show()");
//    array_transf();
    p();
    return x+y;
}
int main() {
    log(FUNC,INFO,"Program is running....", strcolor(RED,"RUNNING!!") );


    exec(show,1,2);



    log(FUNC,INFO,"Program is ending....");
//    cout << strcolor(RED,"xxx") <<endl;
//    printl(RED,"why....","\n");
//    printl(GREEN,"why....","\n");
//    printl(YELLOW,"why....","\n");
//    printl(BLUE,"why....","\n");
//    printl(PINK,"why....","\n");
//    printl(CYAN,"why....","\n");
    int i=0;
    for(i=28;i<=50;i++)
        cout << "\033[0m\033[1;"<< i<<"m"<< i <<"\033[0m" <<",";
    return 0;
}
